﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace SceneTester.Scenes
{
    public class LoadMenu : Scene
    {
        private int sleeptime;
        private Bitmap loadedGraphics;

        private Font stringFont;
        private Brush stringBrush;

        public LoadMenu(Graphics g, Camera camera) : base(g, camera)
        {
            sleeptime = 5000;
            stringFont = new Font(FontFamily.GenericSerif, 12);
            stringBrush = Brushes.White;

            loadedGraphics = new Bitmap(camera.Bounds.Size.Width, camera.Bounds.Size.Height);

            RegisterInputEvents();
            

        }

        private void RegisterInputEvents()
        {
            GameInput input = GameInput.GetInstance();
            input.KeyDownEvent += InputTest;
        }

        private void InputTest(Keys key)
        {
            if (key == Keys.Q)
            {
                OnExitEvent();
                return;
            }

            try
            {
                Graphics.Flush();

                Graphics.DrawImage(loadedGraphics, 0, 0);

                Graphics.DrawString("" + key, stringFont, stringBrush, Camera.Bounds.Width / 2 - 5, 600);
            }
            catch
            {

            }
        }

        public override void Load(Action<int> ProgressCallback)
        {
            ProgressCallback(25);
            Graphics g = Graphics.FromImage(loadedGraphics);
            g.FillRectangle(Brushes.Black, Camera.Bounds);

            ProgressCallback(50);

            g.DrawString("Play!", stringFont, stringBrush, 300, 400);

            ProgressCallback(75);

            Thread.Sleep(sleeptime);

            ProgressCallback(100);
        }

        public override void Play()
        {
            Graphics.DrawImage(loadedGraphics, 0, 0);
        }

        public override void Decompose()
        {
            GameInput input = GameInput.GetInstance();

            input.KeyDownEvent -= InputTest;
        }
    }
}
